# Copyright (c) 2008, Eamonn Faherty
# This is licensed under the MIT licence.

class CheckScore:
	"""Container for checkstyle test score"""
	packageScores = {}
	methodScores = {}
	interfaceScores = {}
	score = 0
	filesRead = 0

	def __init__(self):
		self.score = 0
	
	
	def incrementFileCount(self):
		self.filesRead += 1
		
	def addPackageScore(self, testName, score):
		"""set the results for a package score"""
		self.packageScores[testName] = score
		self.score += score
	
	def addMethodScore(self, testName, score):
		"""set the results for a method score"""
		self.methodScores[testName] = score
		self.score += score
	
	def addInterfaceScore(self, testName, score):
		"""set the results for an interface score"""
		self.interfaceScores[testName] = score
		self.score += score
		
	def printResults(self):
		print "--results--"
		print "files read: ", self.filesRead
		for testName, score in self.packageScores.iteritems():
			print testName, ":",  score
		for name, score in self.methodScores.iteritems():
			print name, ":", score
		for name, score in self.interfaceScores.iteritems():
			print name, ":", score
		print "total score: ", self.score
		print "-----------"
	
class CheckPackage:
	"""Container for package checkstyle tests"""
	def __init__(self):
		pass

	def checkAvoidStarImport(self, package, checkScore):
		"""Check for AvoidStarImport"""
		score = 0
		for stmt in package.imports:
			if stmt.find("*") != -1:
				score = -1
		
		checkScore.addPackageScore("checkAvoidStarImport",score)
		return score

class CheckMethod:
	"""Container for method checkstyle tests"""
	def __init__(self):
		pass

	def checkParameterNumber(self, mtd, checkScore):
		"""Check for ParameterNumber"""
		score = 0
		if (len(mtd.arguments) > 7):
			score = -1
		
		checkScore.addMethodScore("checkParameterNumber",score)
		return score
		
	
class CheckInterface:
	"""Container for interface checkstyle tests"""
	def __init__(self):
		pass

	def checkInterfaceIsType(self, interface, checkScore):
		"""Check that interface is a type"""
		score = 0
		if len(interface.methods)  == 0: 
			score = -1

		checkScore.addInterfaceScore("checkInterfaceIsType",score)
		return score